import currency from 'currency.js';

// 两个数相加
export const add = (a: number, b: number): number => {
  return currency(a).add(b).value;
};

// 两个数相减
export const subtract = (a: number, b: number): number => {
  return currency(a).subtract(b).value;
};

// 两个数相乘
export const multiply = (a: number, b: number): number => {
  return currency(a).multiply(b).value;
};

// 两个数相除
export const divide = (a: number, b: number): number => {
  if (b === 0) {
    throw new Error('除数不能为零');
  }
  return currency(a).divide(b).value;
};

// 格式化金额显示
export const formatCurrency = (
  amount: number,
  options?: currency.Options,
): string => {
  return currency(amount, options).format();
};

// 获取金额的数值
export const getValue = (amount: number): number => {
  return currency(amount).value;
};
